var MetaData = (function(){
	//数据源管理框架
	var __metaData = {
			init : function(module,meta,dataDiv,selectData,pageindex){//初始化
				//对页面进行初始化操作
				if(meta){
					this.load(module,meta,dataDiv,selectData,pageindex);
				}
			},
			load : function(module,meta,dataDiv,selectData,pageindex){//填充数据，渲染模块视图
				this.fetch(module,meta,dataDiv,selectData,pageindex);//填充数据
				this.render();//渲染模块视图
			},
			fetch : function(module,meta,dataDiv,selectData,pageindex){//解析数据
				var data = eval("("+meta+")"); 
				var sData = eval("("+selectData+")"); 
				//console.log("==========fetch data start=========")
				if(module){
					if(this[module].load){
						this[module].data = data;
						this[module].dataDiv = $(dataDiv);
						this[module].dataSelect=sData;
						this[module].pageIndex=pageindex;
					}
				}
				//console.log("==========fetch data end=========")
			},
			render : function(){//渲染模块视图
				for(var prop in this){
					if(this[prop].load){
						this[prop].before&&this[prop].before();//渲染模块前
						this[prop].render();//渲染对应模块
						this[prop].after&&this[prop].after();//渲染模块后
					}
				}
			},
			extend : function(target){//继承 扩展
				for(var prop in target){
					this[prop] = target[prop];
				}
			}
	};
	//将meta数据中对应模块的数据，映射给对应模块的data属性
	var __modules__ = {
			sginList : {
				load : true,
				data : null,//模块对应的数据
				dataDiv : null,
				dataBody : $('body'),
				dataSelect:null,
				pageIndex:1,
				dataSize:30,
				before : function(){
					Date.prototype.Format = function (fmt) {
					    var o = {
					        "M+": this.getMonth() + 1, //月份 
					        "d+": this.getDate(), //日 
					        "h+": this.getHours(), //小时 
					        "m+": this.getMinutes(), //分 
					        "s+": this.getSeconds(), //秒 
					        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
					        "S": this.getMilliseconds() //毫秒 
					    };
					    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
					    for (var k in o)
					    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
					    return fmt;
					}
				},
				render : function(){//渲染模块
					this.data = this.data||[];
					this.dataSelect =this.dataSelect||[];
					var optionText,beanPro;
					for(var key in this.dataSelect){
						beanPro=this.dataSelect[key];
						optionText+='<option value="'+beanPro.projectCode+'">'+beanPro.projectName+'</option>';
					}
					var selectHtml='<select class="selectOption">'+optionText+'</select>';
					var bean,$col;
					var tempSize=this.pageIndex*this.dataSize;
					var key =0;
					if(this.pageIndex >1){
						key = tempSize-this.dataSize;
					}
					for(var i=key;i<tempSize;i++){
						if(i==tempSize){
							break;
						}
						bean=this.data[i];
						if(bean==undefined || bean==null){
							break;
						}
					/*	$col = $('<tr>'+
								'<td>'+bean.jobNumber+'</td>'+
								'<td>'+bean.name+'</td>'+
								'<td><a class="btn btn-primary" href="#" role="button"  onclick="toWorkClick('+bean.id+')" >上班</a></td>'+
								'<td><a class="btn btn-primary" href="#" role="button" onclick="offWorkClick('+bean.id+')" >下班</a></td>'+
								'<td><a class="btn btn-primary" data-toggle="modal" href="signDetails?eId='+bean.id+'"  data-target="#exampleModal">查看详情</a></td>'+		
								'</tr>');
						this.dataDiv.append($col);*/
						
						$col = $('<div class="col-sm-6 col-md-3"><div class="thumbnail">'+
								  '<div class="caption text-center">'+
								  	'<p>编号:'+bean.jobNumber+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名:'+bean.name+'</p>'+
								  	'<p id="block'+bean.id+'">服务项目:'+selectHtml+'</p>'+
							        '<p><a class="btn btn-primary btn-sm" href="#" role="button"  onclick="toWorkClick('+bean.id+')" >上班</a>&nbsp;&nbsp;<a class="btn btn-primary btn-sm" href="#" role="button" onclick="offWorkClick('+bean.id+')" >下班</a></p>'+
							        '<p><a class="btn btn-primary btn-sm" data-toggle="modal" href="signDetails?eId='+bean.id+'"  data-target="#exampleModal">查看详情</a></p>'+
							       '</div>'+
								' </div></div>');
						 this.dataDiv.append($col);
					}
				},
				after : function(){
					$modal='<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">'+
					    '<div class="modal-dialog">'+
					    '<div class="modal-content">'+
					    '<div class="modal-header">'+
			                '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'+
			                '<h4 class="modal-title" id="myModalLabel">请等待加载中...</h4>'+
			            '</div>'+
			            '<div class="modal-body"></div>'+
			            '<div class="modal-footer">'+
			                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'+
					    '</div>'+
					    '</div>'+
					    '</div>'+
					    '</div>';
					$excelModal='<div class="modal fade" id="excelModal" tabindex="-1" role="dialog" aria-labelledby="myExcelModal" aria-hidden="true">'+
					    '<div class="modal-dialog modal-sm">'+
					    '<div class="modal-content">'+
					    '<div class="modal-header">'+
			                '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'+
			                '<h4 class="modal-title">导出提示框</h4>'+
			            '</div>'+
			            '<div class="modal-body"></div>'+
			            '<div class="modal-footer">'+
			            	'<button type="button" class="btn btn-success" id="clickSuccessBut">确定</button>'+
			                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'+
					    '</div>'+
					    '</div>'+
					    '</div>'+
					    '</div>';
					$importExcelModal='<div class="modal fade" id="importExcelModal" tabindex="-1" role="dialog" aria-labelledby="myImportExcelModal" aria-hidden="true">'+
					    '<div class="modal-dialog modal-sm">'+
					    '<div class="modal-content">'+
					    '<div class="modal-header">'+
			                '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'+
			                '<h4 class="modal-title">导入</h4>'+
			            '</div>'+
			            '<div class="modal-body"></div>'+
			            '<div class="modal-footer">'+
			            	'<button type="button" class="btn btn-success" id="impSuccessBut">确定</button>'+
			                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'+
					    '</div>'+
					    '</div>'+
					    '</div>'+
					    '</div>';
					this.dataBody.append($modal);
					this.dataBody.append($excelModal);
					this.dataBody.append($importExcelModal);
				}
			}//列表数据模块
	};
	__metaData.extend(__modules__);
	return __metaData;
})();